package boun.center;

import java.io.IOException;
import java.text.ParseException;

import org.json.JSONException;

import android.app.Activity;
import android.app.ProgressDialog;
import android.os.AsyncTask;
import android.os.Bundle;
import android.widget.ListView;

public class TwitterActivity extends Activity {
	ListView lv;
	@Override
	public void onCreate(Bundle savedInstanceState){
		super.onCreate(savedInstanceState);
		setContentView(R.layout.tweet_list);
		lv = (ListView)findViewById(R.id.list_tweet);
		new FetchingTask().execute();
	}
	
	class FetchingTask extends AsyncTask<Void,Void,TwitterAdapter>{
		ProgressDialog dialog;
		public FetchingTask(){
			dialog = new ProgressDialog(TwitterActivity.this);
		}
		@Override
		protected TwitterAdapter doInBackground(Void... params) {
			TwitterAdapter ca;
			try {
				try {
					ca = new TwitterAdapter(TwitterActivity.this);
					return ca;
				} catch (ParseException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				} catch (JSONException e) {
					// TODO Auto-generated catch block
					e.printStackTrace();
				}
				
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			return null;
		}
		@Override
		protected void onPreExecute(){
			dialog = ProgressDialog.show(getParent(),"","Fetching..",true);
		}
		@Override
		protected void onPostExecute(TwitterAdapter la){
			dialog.dismiss();
			lv.setAdapter(la);
		}
	}
}
